﻿using System;
using System.Globalization;
using System.Windows.Data;
using CardPlay.Model.CardModel;

namespace CardPlay.Client.Converters
{
    public class RankToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var rank = value as Rank?;
            if (rank == null) return String.Empty;

            return (rank.Value == Rank.Ace || rank.Value > Rank.Ten)
                ? rank.Value.ToString().Substring(0, 1)
                : ((int) rank.Value).ToString(CultureInfo.InvariantCulture);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}